<?php
/**
 * Created by PhpStorm.
 * User: 戎大富
 * Date: 2019/1/2
 * Time: 11:19
 */
namespace app\admin\controller;
use think\Db;
class Work extends Base {

    public function index(){
        if(request()->isAjax()){
            extract(input());
            $page = input('page') ? input('page'):1;
            $limit = input("limit")?input("limit"):10;// 获取总条数;
            $count = Db::table('up_template')
                ->count();//计算总页面
            $list = Db::table('up_template')
                ->page($page, $limit)
                ->select();
            foreach ($list as $key=>&$vo){
                $aa = explode(".",$vo['t_path']);
                $vo['suffix'] = $aa[count($aa)-1];
            }
            return json(['code'=>0,'msg'=>'','count'=>$count,'data'=>$list]);
        }
        return $this->fetch();
    }

    /******
     * @return mixed|\think\response\Json
     */
    public function add(){
        if(request()->isPost()){
            $data['t_name'] = input('param.t_name');
            $data['t_path'] = input('param.img_file');
            $data['t_create_time'] = date('Y-m-d H:i:s',time());
            $res = Db::table('up_template')->insertGetId($data);
            if($res){
                return json(['code' => 200, 'data' =>"", 'msg' => '添加成功']);
            }else{
                return json(['code' => 100, 'data' => '', 'msg' => '添加失败']);
            }
        }
        return $this->fetch();

    }
}